using System;
using System.Collections.Generic;
using System.Text;

namespace ExperimentManager {
  class Generalizer {
    public static int SuccessorDepth;
    public static double LMSn;

    // Provadi aktualizaci vahovych koeficientu
    public static void UpdateWeights(ref int[] currentWeights, List<TrainingExample> trainingExamples) {
      int trainingExampleNumber = 0;
      while (trainingExampleNumber + Generalizer.SuccessorDepth < trainingExamples.Count) {

        int VTrain = 0;

        // spocita hodnotu VTrain
        VTrain = Generalizer.EvaluateTrainingExample(currentWeights, trainingExamples[trainingExampleNumber + Generalizer.SuccessorDepth]);

        // spocita hodnotu V s pruhem
        int V = Generalizer.EvaluateTrainingExample(currentWeights, trainingExamples[trainingExampleNumber]);

        // prepocita vahove koeficienty (algoritmus LMS)
        for (int i = 0; i < currentWeights.Length; i++) {
          currentWeights[i] += ( int )Math.Round(Generalizer.LMSn * (VTrain - V) * trainingExamples[trainingExampleNumber].fitnessComponents[i]);
        }

        trainingExampleNumber++;
      }
    }

    // ohodnoti treninkovy priklad
    private static int EvaluateTrainingExample(int[] currentWeights, TrainingExample te) {
      int result = 0;
      for (int i = 0; i < currentWeights.Length; i++) {
        result += currentWeights[i] * te.fitnessComponents[i];
      }

      return result;
    }

  }
}
